package com.android.examplelist;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;


// 官方网站：http://loopj.com/android-async-http/

public class AsyncHttpClientActivity extends Activity implements IAsyncHttp {

	Button asyncHttpButton;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.async_http);
		
		
		asyncHttpButton = (Button) findViewById(R.id.async_http);
		
		ActionBar actionBar = getActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		
		AsyncHttpHelper.getInstance().getData("http://g.cn", this);
		
		//NewsEntity.getData("http://g.cn", this);
		
		/*
		AsyncHttpClient client = new AsyncHttpClient();  
        client.get("http://www.baidu.com", new AsyncHttpResponseHandler() {  
              
            @Override  
            public void onStart() {  
                super.onStart();  
                System.out.println("onStart");  
                
                asyncHttpButton.setVisibility(View.GONE);
                
            }  
              
            @Override  
            public void onFinish() {  
                super.onFinish();  
                System.out.println("onFinish");  
                
                asyncHttpButton.setVisibility(View.VISIBLE);
                
            }

			@Override
			public void onFailure(int arg0, Header[] arg1, byte[] arg2,
					Throwable arg3) {
				
				System.out.println("onFailure");  
				// TODO Auto-generated method stub
                asyncHttpButton.setText("失败"); 
				
			}

			
			@Override
			public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
				// TODO Auto-generated method stub
				String html = new String(arg2);
				System.out.println(html);
				System.out.println("onSuccess");  
				asyncHttpButton.setText("成功"); 
				
			}  
			

              
        });*/
		
	}
		

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case android.R.id.home:
				finish();
				return true;
			case R.id.action_settings:
				return true;
		}
		
		return super.onOptionsItemSelected(item);
	 }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onStart1() {
		System.out.println("onStart1回调");  
		
	}

	@Override
	public void onFinish1() {
		System.out.println("onFinish1回调");  
		
	}

	@Override
	public void onFailure1() {
		System.out.println("onFailure1回调");  
		
	}

	@Override
	public void onSuccess1(String data) {
		System.out.println("onSuccess1回调");  
		
	}

}
